package com.atwork.service.impl;

import com.atwork.dao.SysResourceDao;
import com.atwork.model.normal.SysResource;
import com.atwork.model.vo.ShiroUser;
import com.atwork.service.ShiroUserService;
import com.atwork.service.SysResourceService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @CreateBy: zhaojun
 * @CreateTime: 2018-08-04
 * @Desc: 系统资源模块
 */
@Service
@Slf4j
public class SysResourceServiceImpl implements SysResourceService {
    @Autowired
    private SysResourceDao sysResourceDao;

    @Autowired
    private ShiroUserService shiroUserService;
    @Override
    public List<SysResource> getAllResource(int pageNum, int pageSize) {
        log.info("获取全部系统菜单");
        PageHelper.startPage(pageNum,pageSize);
        return sysResourceDao.getAllResource();
    }

    @Override
    public int insertResource(SysResource record) {
        return sysResourceDao.insertResource(record);
    }

    @Override
    public SysResource getResourceById(Integer id) {
        log.info("通过id获取系统菜单");
        return sysResourceDao.getResourceById(id);
    }

    @Override
    public int updateResourceById(SysResource record) {
        return sysResourceDao.updateResourceById(record);
    }

    @Override
    public Set<SysResource> getResourceTree(String loginName) {
        log.info("获取左侧权限树");
        ShiroUser shiroUser = shiroUserService.getShiroUser(loginName);//正式启动时，放开
        return shiroUser.getSysResource();
    }
}
